Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

workflow which ensures that talawa Api app starts in docker #2759

Open
wants to merge 24 commits into
base: develop
Choose a base branch
from

Conversation

prayanshchh
Copy link

@prayanshchh prayanshchh commented Dec 14, 2024

What kind of change does this PR introduce?
Changing workflow to ensure that talawa api starts in docker

Issue Number:
#2638

Fixes #

Did you add tests for your changes?
No

Snapshots/Videos:

If relevant, did you update the documentation?

Summary

Does this PR introduce a breaking change?

Other information

Have you read the contributing guide?

Summary by CodeRabbit

  • New Features

    • Introduced a new Docker-Check job in the GitHub Actions workflow to enhance Docker setup and verification.
    • Added a prompt for users to specify a working directory (PWD) during Docker setup.
    • New environment variable PWD added to the sample environment configuration.
  • Bug Fixes

    • Corrected minor syntax issues in the Docker-Check job configuration.
  • Tests

    • Updated test volunteer hours to reflect the current date instead of the previous day, improving accuracy in volunteer hour tracking.
  • Changes

    • Updated docker-compose.dev.yaml to modify service configurations, including port mappings and database URL structure.
    • Removed the caddy service from the Docker configuration.

Copy link

coderabbitai bot commented Dec 14, 2024

Walkthrough

This pull request introduces a new Docker-Check job to the GitHub Actions workflow for the Talawa API project. The job ensures that the application can successfully start in a Docker environment by performing comprehensive checks. It verifies the Docker Compose setup, checks the health of MongoDB and Redis services, and confirms that the Talawa API can be launched correctly. The workflow runs after the existing Test-Application job and provides an additional layer of validation for the project's Docker deployment.

Changes

File Change Summary
.github/workflows/pull-request.yml Added Docker-Check job with Docker startup and health verification steps, including minor syntax corrections.
tests/helpers/volunteers.ts Updated volunteer hours handling to use the current date instead of yesterday, ensuring accurate tracking in tests.
.env.sample Introduced new environment variable PWD for setting the working directory in Docker, with formatting adjustments.
docker-compose.dev.yaml Modified talawa-api-dev service with new port mapping and updated MONGO_DB_URL; removed caddy service and associated volumes.
setup.ts Added prompt for user-defined working directory (PWD) during Docker setup, updating logs and configuration accordingly.

Possibly related issues

Possibly related PRs

Suggested reviewers

  • palisadoes

Poem

🐰 Docker's dance, a workflow's delight,
Containers spinning, checking all's right
MongoDB, Redis, API in sync
No more deployment worries to think!
A rabbit's CI/CD dream takes flight 🚀


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

Our Pull Request Approval Process

Thanks for contributing!

Testing Your Code

Remember, your PRs won't be reviewed until these criteria are met:

  1. We don't merge PRs with poor code quality.
    1. Follow coding best practices such that CodeRabbit.ai approves your PR.
  2. We don't merge PRs with failed tests.
    1. When tests fail, click on the Details link to learn more.
    2. Write sufficient tests for your changes (CodeCov Patch Test). Your testing level must be better than the target threshold of the repository
    3. Tests may fail if you edit sensitive files. Ask to add the ignore-sensitive-files-pr label if the edits are necessary.
  3. We cannot merge PRs with conflicting files. These must be fixed.

Our policies make our code better.

Reviewers

Do not assign reviewers. Our Queue Monitors will review your PR and assign them.
When your PR has been assigned reviewers contact them to get your code reviewed and approved via:

  1. comments in this PR or
  2. our slack channel

Reviewing Your Code

Your reviewer(s) will have the following roles:

  1. arbitrators of future discussions with other contributors about the validity of your changes
  2. point of contact for evaluating the validity of your work
  3. person who verifies matching issues by others that should be closed.
  4. person who gives general guidance in fixing your tests

CONTRIBUTING.md

Read our CONTRIBUTING.md file. Most importantly:

  1. PRs with issues not assigned to you will be closed by the reviewer
  2. Fix the first comment in the PR so that each issue listed automatically closes

Other

  1. 🎯 Please be considerate of our volunteers' time. Contacting the person who assigned the reviewers is not advised unless they ask for your input. Do not @ the person who did the assignment otherwise.
  2. Read the CONTRIBUTING.md file make

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 5

🧹 Outside diff range and nitpick comments (2)
.github/workflows/pull-request.yml (2)

366-372: Use environment variable for health check URL

The health check URL is hardcoded. Consider using the HEALTH_CHECK_URL environment variable:

-until docker-compose -f docker-compose.dev.yaml exec -T talawa-api-dev curl -sf "http://talawa-api-dev:4000/health" 2>&1 || [ $timeout -eq 0 ]; do
+until docker-compose -f docker-compose.dev.yaml exec -T talawa-api-dev curl -sf "${HEALTH_CHECK_URL}/health" 2>&1 || [ $timeout -eq 0 ]; do
🧰 Tools
🪛 actionlint (1.7.4)

372-372: could not parse as YAML: yaml: line 372: could not find expected ':'

(syntax-check)

🪛 yamllint (1.35.1)

[error] 366-366: trailing spaces

(trailing-spaces)


392-407: Fix environment variables indentation

The env: section should be at the same level as steps::

-  env:
-      HEALTH_CHECK_URL: http://localhost:4000
-      COMPOSE_PROJECT_NAME: pr-${{ github.event.pull_request.number }}
+    env:
+      HEALTH_CHECK_URL: http://localhost:4000
+      COMPOSE_PROJECT_NAME: pr-${{ github.event.pull_request.number }}
🧰 Tools
🪛 yamllint (1.35.1)

[error] 407-407: trailing spaces

(trailing-spaces)

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6bd0fec and 4fa5812.

📒 Files selected for processing (1)
  • .github/workflows/pull-request.yml (1 hunks)
🧰 Additional context used
🪛 actionlint (1.7.4)
.github/workflows/pull-request.yml

372-372: could not parse as YAML: yaml: line 372: could not find expected ':'

(syntax-check)

🪛 yamllint (1.35.1)
.github/workflows/pull-request.yml

[error] 322-322: trailing spaces

(trailing-spaces)


[error] 323-323: trailing spaces

(trailing-spaces)


[error] 327-327: trailing spaces

(trailing-spaces)


[error] 366-366: trailing spaces

(trailing-spaces)


[error] 407-407: trailing spaces

(trailing-spaces)


[error] 374-374: syntax error: could not find expected ':'

(syntax)

.github/workflows/pull-request.yml Outdated Show resolved Hide resolved
.github/workflows/pull-request.yml Outdated Show resolved Hide resolved
.github/workflows/pull-request.yml Outdated Show resolved Hide resolved
.github/workflows/pull-request.yml Outdated Show resolved Hide resolved
.github/workflows/pull-request.yml Outdated Show resolved Hide resolved
@prayanshchh
Copy link
Author

making changes as suggested

…ansh-talawa-api into api_fail_docker

merge# Please enter a commit message to explain why this merge is necessary,
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Outside diff range and nitpick comments (2)
.github/workflows/pull-request.yml (2)

311-320: Optimize cache configuration

Consider adding package-lock.json to the cache key for better cache hits.

 - name: Cache Node.js dependencies
   uses: actions/cache@v4
   with:
     path: |
       ~/.npm
       node_modules
-    key: ${{ runner.os }}-docker-check-${{ hashFiles('**/package-lock.json') }}
+    key: ${{ runner.os }}-docker-check-node-${{ hashFiles('package-lock.json') }}
     restore-keys: |
-      ${{ runner.os }}-docker-check-
+      ${{ runner.os }}-docker-check-node-

333-337: Improve error handling in container startup

Consider capturing and displaying the exit code for better debugging.

-if ! timeout 300 docker-compose -f docker-compose.dev.yaml up -d --build; then
+if ! timeout 300 docker-compose -f docker-compose.dev.yaml up -d --build; then
+  exit_code=$?
   echo "Failed to start containers"
+  echo "Exit code: $exit_code"
   docker-compose -f docker-compose.dev.yaml logs
   exit 1
 fi
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4fa5812 and 57ae541.

📒 Files selected for processing (1)
  • .github/workflows/pull-request.yml (1 hunks)
🧰 Additional context used
🪛 actionlint (1.7.4)
.github/workflows/pull-request.yml

372-372: could not parse as YAML: yaml: line 372: could not find expected ':'

(syntax-check)

🪛 yamllint (1.35.1)
.github/workflows/pull-request.yml

[error] 322-322: trailing spaces

(trailing-spaces)


[error] 323-323: trailing spaces

(trailing-spaces)


[error] 327-327: trailing spaces

(trailing-spaces)


[error] 366-366: trailing spaces

(trailing-spaces)


[error] 407-407: trailing spaces

(trailing-spaces)


[error] 374-374: syntax error: could not find expected ':'

(syntax)

🔇 Additional comments (2)
.github/workflows/pull-request.yml (2)

307-307: Fix action step configuration syntax

The Node.js setup step has incorrect syntax.

-- uses: actions/setup-node@v4
+ - uses: actions/setup-node@v4

392-407: Verify environment variable configuration

Please verify that these environment variables match the ones in docker-compose.dev.yaml.

🧰 Tools
🪛 yamllint (1.35.1)

[error] 407-407: trailing spaces

(trailing-spaces)

.github/workflows/pull-request.yml Outdated Show resolved Hide resolved
.github/workflows/pull-request.yml Outdated Show resolved Hide resolved
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

🧹 Outside diff range and nitpick comments (2)
.github/workflows/pull-request.yml (2)

393-407: LGTM: Environment variables are well configured

The environment variables are properly set with appropriate use of secrets. Just remove trailing spaces at line 407.

-      MAIL_PASSWORD: ${{secrets.MAIL_PASSWORD}}
-             
+      MAIL_PASSWORD: ${{secrets.MAIL_PASSWORD}}

299-407: Consider enhancing the Docker health check implementation

Some suggestions to improve the implementation:

  1. Consider using Docker's built-in HEALTHCHECK instruction in Dockerfile instead of shell-based health checks
  2. Consider implementing exponential backoff for health checks instead of fixed intervals
  3. Consider adding container resource limits to prevent resource exhaustion

These changes would make the health checks more robust and maintainable.

🧰 Tools
🪛 actionlint (1.7.4)

372-372: could not parse as YAML: yaml: line 372: could not find expected ':'

(syntax-check)

🪛 yamllint (1.35.1)

[error] 322-322: trailing spaces

(trailing-spaces)


[error] 323-323: trailing spaces

(trailing-spaces)


[error] 327-327: trailing spaces

(trailing-spaces)


[error] 366-366: trailing spaces

(trailing-spaces)


[error] 374-374: syntax error: could not find expected ':'

(syntax)

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 57ae541 and cfec867.

📒 Files selected for processing (1)
  • .github/workflows/pull-request.yml (1 hunks)
🧰 Additional context used
🪛 actionlint (1.7.4)
.github/workflows/pull-request.yml

372-372: could not parse as YAML: yaml: line 372: could not find expected ':'

(syntax-check)

🪛 yamllint (1.35.1)
.github/workflows/pull-request.yml

[error] 322-322: trailing spaces

(trailing-spaces)


[error] 323-323: trailing spaces

(trailing-spaces)


[error] 327-327: trailing spaces

(trailing-spaces)


[error] 366-366: trailing spaces

(trailing-spaces)


[error] 408-408: trailing spaces

(trailing-spaces)


[error] 374-374: syntax error: could not find expected ':'

(syntax)

🔇 Additional comments (2)
.github/workflows/pull-request.yml (2)

299-320: LGTM: Job configuration follows best practices

The job configuration is well-structured with proper dependency management and caching strategy.


353-364: ⚠️ Potential issue

Fix Redis health check syntax

There's a syntax error in the if condition:

-          if[ $timeout -eq 0 ]; then
+          if [ $timeout -eq 0 ]; then

Likely invalid or redundant comment.

.github/workflows/pull-request.yml Outdated Show resolved Hide resolved
.github/workflows/pull-request.yml Outdated Show resolved Hide resolved
.github/workflows/pull-request.yml Outdated Show resolved Hide resolved
.github/workflows/pull-request.yml Outdated Show resolved Hide resolved
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Outside diff range and nitpick comments (2)
.github/workflows/pull-request.yml (2)

321-337: Fix formatting and enhance error logging.

  1. Remove trailing spaces after run : and in the if condition
  2. Add container logs to the error message when docker-compose file is not found
-        run : | 
+        run: |
           # Ensure no containers are running
           docker-compose -f docker-compose.dev.yaml down -v || true

           # Verify docker-compose file exists
-          if [ ! -f "docker-compose.dev.yaml" ]; then 
+          if [ ! -f "docker-compose.dev.yaml" ]; then
             echo "Error: docker-compose.dev.yaml not found"
+            docker-compose -f docker-compose.dev.yaml logs
             exit 1
           fi
🧰 Tools
🪛 yamllint (1.35.1)

[error] 322-322: trailing spaces

(trailing-spaces)


[error] 327-327: trailing spaces

(trailing-spaces)


366-382: Enhance API health check implementation.

Consider adding additional health check parameters to ensure comprehensive API readiness:

  1. Add request timeout to curl command
  2. Check for specific health check response content
-          until docker-compose -f docker-compose.dev.yaml exec -T talawa-api-dev curl -sf "http://localhost:4000/health" 2>&1 || [ $timeout -eq 0 ]; do
+          until docker-compose -f docker-compose.dev.yaml exec -T talawa-api-dev curl -sf --max-time 5 "http://localhost:4000/health" 2>&1 | grep -q '"status":"healthy"' || [ $timeout -eq 0 ]; do
🧰 Tools
🪛 yamllint (1.35.1)

[error] 366-366: trailing spaces

(trailing-spaces)

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between cfec867 and 1544502.

📒 Files selected for processing (1)
  • .github/workflows/pull-request.yml (1 hunks)
🧰 Additional context used
🪛 actionlint (1.7.4)
.github/workflows/pull-request.yml

384-384: could not parse as YAML: yaml: line 384: could not find expected ':'

(syntax-check)

🪛 yamllint (1.35.1)
.github/workflows/pull-request.yml

[error] 322-322: trailing spaces

(trailing-spaces)


[error] 327-327: trailing spaces

(trailing-spaces)


[error] 366-366: trailing spaces

(trailing-spaces)


[error] 409-409: trailing spaces

(trailing-spaces)


[error] 388-388: syntax error: could not find expected ':'

(syntax)

🔇 Additional comments (2)
.github/workflows/pull-request.yml (2)

299-320: LGTM! Job configuration follows best practices.

The job configuration is well-structured with proper dependency setup, Node.js configuration, and dependency caching.


299-409: Overall implementation achieves the PR objective.

The Docker check implementation successfully verifies that the Talawa API starts correctly in a Docker environment. It includes proper health checks, timeouts, and cleanup procedures. The remaining issues are mostly syntax and formatting related, which have been addressed in previous comments.

🧰 Tools
🪛 actionlint (1.7.4)

384-384: could not parse as YAML: yaml: line 384: could not find expected ':'

(syntax-check)

🪛 yamllint (1.35.1)

[error] 322-322: trailing spaces

(trailing-spaces)


[error] 327-327: trailing spaces

(trailing-spaces)


[error] 366-366: trailing spaces

(trailing-spaces)


[error] 409-409: trailing spaces

(trailing-spaces)


[error] 388-388: syntax error: could not find expected ':'

(syntax)

.github/workflows/pull-request.yml Outdated Show resolved Hide resolved
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (2)
.github/workflows/pull-request.yml (2)

367-380: Fix indentation in API health check.

The indentation is inconsistent in this section, which affects readability.

-            # Wait for TALAWA API to be healthy 
-          until docker-compose -f docker-compose.dev.yaml exec -T talawa-api-dev curl -sf "http://localhost:4000/health" 2>&1 || [ $timeout -eq 0 ]; do
-            echo "Waiting for API to start... ($timeout seconds remaining)"
-            sleep 1
-            ((timeout--))
-           done
+          # Wait for TALAWA API to be healthy 
+          until docker-compose -f docker-compose.dev.yaml exec -T talawa-api-dev curl -sf "http://localhost:4000/health" 2>&1 || [ $timeout -eq 0 ]; do
+            echo "Waiting for API to start... ($timeout seconds remaining)"
+            sleep 1
+            ((timeout--))
+          done
🧰 Tools
🪛 yamllint (1.35.1)

[error] 367-367: trailing spaces

(trailing-spaces)


394-409: Fix trailing spaces in environment variables section.

Remove trailing spaces to maintain consistent formatting.

-        MAIL_PASSWORD: ${{secrets.MAIL_PASSWORD}}
-             
+        MAIL_PASSWORD: ${{secrets.MAIL_PASSWORD}}
+
🧰 Tools
🪛 yamllint (1.35.1)

[warning] 395-395: wrong indentation: expected 6 but found 8

(indentation)


[error] 409-409: trailing spaces

(trailing-spaces)

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1544502 and 0b6ef08.

📒 Files selected for processing (1)
  • .github/workflows/pull-request.yml (1 hunks)
🧰 Additional context used
🪛 actionlint (1.7.4)
.github/workflows/pull-request.yml

322-322: shellcheck reported issue in this script: SC1069:error:38:3: You need a space before the [

(shellcheck)

🪛 yamllint (1.35.1)
.github/workflows/pull-request.yml

[error] 367-367: trailing spaces

(trailing-spaces)


[warning] 395-395: wrong indentation: expected 6 but found 8

(indentation)


[error] 409-409: trailing spaces

(trailing-spaces)

🔇 Additional comments (5)
.github/workflows/pull-request.yml (5)

299-320: LGTM! Job configuration follows best practices.

The job configuration is well-structured with proper dependency management, Node.js setup, and dependency caching.


321-338: LGTM! Docker startup implementation is robust.

The implementation includes proper error handling, timeouts, and cleanup of existing containers.

🧰 Tools
🪛 actionlint (1.7.4)

322-322: shellcheck reported issue in this script: SC1069:error:38:3: You need a space before the [

(shellcheck)


343-343: Fix MongoDB health check syntax.

There's a syntax error in the until condition that needs to be fixed.

-until docker-compose -f docker-compose.dev.yaml exec -T mongodb mongo --eval "db.runCommand('ping').ok">/dev/null 2>&1 || [ $timeout -eq 0]; do
+until docker-compose -f docker-compose.dev.yaml exec -T mongodb mongo --eval "db.runCommand('ping').ok" >/dev/null 2>&1 || [ $timeout -eq 0 ]; do

360-365: Fix Redis health check syntax and indentation.

There are syntax errors in the Redis health check implementation.

-if[ $timeout -eq 0 ]; then
+if [ $timeout -eq 0 ]; then

384-393: LGTM! Cleanup implementation follows best practices.

The cleanup function correctly preserves the exit code and uses trap for proper cleanup on script exit.

@Cioppolo14
Copy link
Contributor

There isn’t an issue assigned to you for this PR. Please follow the guidelines in our PR_GUIDELINES.md file. We have the procedures in place so that everyone has a fair chance of contributing. I will be closing this pull request. Please follow the procedures and resubmit when ready.

@Cioppolo14 Cioppolo14 closed this Dec 14, 2024
@prayanshchh
Copy link
Author

@Cioppolo14 I accidently tagged the wrong issue, but I am assigned to this issue: #2638..please re-open this

@palisadoes palisadoes reopened this Dec 15, 2024
@palisadoes
Copy link
Contributor

Please make sure all tests pass and coderabbit.ai approves the PR

@prayanshchh
Copy link
Author

Please make sure all tests pass and coderabbit.ai approves the PR

yes sir, will get this ready 5-6 days

@bandhan-majumder
Copy link

bandhan-majumder commented Dec 17, 2024

Hi @prayanshchh . Have you found any solution for GraphQLError: Syntax Error: Unexpected <EOF>. ?? I came across this Type-Checker failure today and noticed all the previous PRs are failing this check too.

@prayanshchh
Copy link
Author

Hi @prayanshchh . Have you found any solution for GraphQLError: Syntax Error: Unexpected <EOF>. ?? I came across this Type-Checker failure today and noticed all the previous PRs are failing this check too.

is that so, then ig this should be a seperate issue then, can u give ur PR link

@bandhan-majumder
Copy link

Sure. I have opened an issue regarding this since a few others also reported the same in slack.

@VanshikaSabharwal
Copy link

If you need any assistance feel free to reach out to me @prayanshchh @bandhan-majumder .

@palisadoes
Copy link
Contributor

Please fix:

  1. Any failing tests (Click on the details link for more information)
  2. Any conflicting files

Make sure CodeRabbit.ai approves your changes

@palisadoes
Copy link
Contributor

There is only one conflicting file. Please make your modifications and keep this PR open.

Copy link

codecov bot commented Dec 21, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.74%. Comparing base (4b5c74f) to head (4c7280c).

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #2759   +/-   ##
========================================
  Coverage    97.74%   97.74%           
========================================
  Files          358      358           
  Lines        18103    18103           
  Branches      2596     2596           
========================================
  Hits         17695    17695           
  Misses         404      404           
  Partials         4        4           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (3)
.github/workflows/pull-request.yml (3)

321-325: Fix trailing spaces in the run command.

Remove trailing spaces after the pipe operator.

-        run: | 
+        run: |

389-398: Fix indentation in cleanup function.

The cleanup function implementation is good but needs formatting fixes:

-            }
+          }

399-414: Fix environment variables indentation.

The environment variables section has inconsistent indentation:

-        HEALTH_CHECK_URL: http://localhost:4000
+      HEALTH_CHECK_URL: http://localhost:4000
-             
+
🧰 Tools
🪛 yamllint (1.35.1)

[warning] 400-400: wrong indentation: expected 6 but found 8

(indentation)


[error] 414-414: trailing spaces

(trailing-spaces)

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 338a7b8 and 5c54d6a.

📒 Files selected for processing (1)
  • .github/workflows/pull-request.yml (1 hunks)
🧰 Additional context used
🪛 actionlint (1.7.4)
.github/workflows/pull-request.yml

327-327: shellcheck reported issue in this script: SC1069:error:38:3: You need a space before the [

(shellcheck)

🪛 yamllint (1.35.1)
.github/workflows/pull-request.yml

[error] 372-372: trailing spaces

(trailing-spaces)


[warning] 400-400: wrong indentation: expected 6 but found 8

(indentation)


[error] 414-414: trailing spaces

(trailing-spaces)

🔇 Additional comments (4)
.github/workflows/pull-request.yml (4)

299-320: LGTM! Job setup and caching configuration looks good.

The job configuration follows best practices with proper dependency management and caching strategy.


326-343: LGTM! Robust Docker container management implementation.

The implementation includes:

  • Proper cleanup of existing containers
  • File existence verification
  • Timeout for container startup
  • Error logging
🧰 Tools
🪛 actionlint (1.7.4)

327-327: shellcheck reported issue in this script: SC1069:error:38:3: You need a space before the [

(shellcheck)


344-388: ⚠️ Potential issue

Fix syntax and indentation issues in health checks.

There are several syntax and indentation issues in the health checks:

-          if[ $timeout -eq 0 ]; then
+          if [ $timeout -eq 0 ]; then

-            # Wait for TALAWA API to be healthy 
+          # Wait for TALAWA API to be healthy

-          until docker-compose -f docker-compose.dev.yaml exec -T talawa-api-dev curl -sf "http://localhost:4000/health" 2>&1 || [ $timeout -eq 0 ]; do
+          until docker-compose -f docker-compose.dev.yaml exec -T talawa-api-dev curl -sf "http://localhost:4000/health" 2>&1 || [ $timeout -eq 0 ]; do

Likely invalid or redundant comment.

🧰 Tools
🪛 yamllint (1.35.1)

[error] 372-372: trailing spaces

(trailing-spaces)


399-414: Verify Docker configuration alignment.

Let's verify that the Docker configuration matches the environment variables:

✅ Verification successful

Docker configuration is properly aligned with environment variables

The verification confirms that the Docker configuration aligns correctly with the environment variables in the GitHub workflow:

  • MongoDB configuration matches (mongodb:27017)
  • Redis service name and port are correctly configured (redis-stack-server:6379)
  • API port 4000 is properly exposed in both Dockerfile.dev and docker-compose.prod.yaml
  • All required services (mongodb, redis-stack-server) are present with correct networking
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify Docker configuration matches environment variables

# Check if docker-compose file exists and contains the required services
if [ -f "docker-compose.dev.yaml" ]; then
  echo "Checking service configuration..."
  
  # Verify MongoDB configuration
  if ! grep -q "mongodb:27017" docker-compose.dev.yaml; then
    echo "Warning: MongoDB port configuration mismatch"
  fi
  
  # Verify Redis configuration
  if ! grep -q "redis-stack-server" docker-compose.dev.yaml; then
    echo "Warning: Redis service name mismatch"
  fi
  
  # Verify API port configuration
  if ! grep -q "4000" docker-compose.dev.yaml; then
    echo "Warning: API port configuration missing"
  fi
fi

Length of output: 342


Script:

#!/bin/bash
# Let's examine the docker-compose.dev.yaml content to better understand the configuration
cat docker-compose.dev.yaml

# Also check if there's a regular docker-compose.yaml
if [ -f "docker-compose.yaml" ]; then
  echo -e "\n=== docker-compose.yaml content ===\n"
  cat docker-compose.yaml
fi

# Let's also check for any other docker-compose files
fd docker-compose

Length of output: 1564


Script:

#!/bin/bash
# Let's check the production docker compose file as well
cat docker-compose.prod.yaml

# And let's verify if there are any port mappings in the Dockerfile.dev
cat Dockerfile.dev

Length of output: 1387

🧰 Tools
🪛 yamllint (1.35.1)

[warning] 400-400: wrong indentation: expected 6 but found 8

(indentation)


[error] 414-414: trailing spaces

(trailing-spaces)

@palisadoes
Copy link
Contributor

Please fix the failing test

@prayanshchh
Copy link
Author

Please fix the failing test

yes sir

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (2)
.github/workflows/pull-request.yml (2)

311-320: Enhance cache key strategy

Consider adding package-lock.json version to the cache key for more precise caching:

-          key: ${{ runner.os }}-docker-check-${{ hashFiles('**/package-lock.json') }}
+          key: ${{ runner.os }}-docker-check-v1-${{ hashFiles('**/package-lock.json') }}
           restore-keys: |
-            ${{ runner.os }}-docker-check-
+            ${{ runner.os }}-docker-check-v1-

405-420: Fix trailing spaces in environment variables section

Remove trailing spaces to maintain consistent formatting:

-      HEALTH_CHECK_URL: http://localhost:4000 
+      HEALTH_CHECK_URL: http://localhost:4000
-      MAIL_PASSWORD: ${{secrets.MAIL_PASSWORD}} 
+      MAIL_PASSWORD: ${{secrets.MAIL_PASSWORD}}
🧰 Tools
🪛 yamllint (1.35.1)

[error] 420-420: trailing spaces

(trailing-spaces)

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5c54d6a and c942e2c.

📒 Files selected for processing (1)
  • .github/workflows/pull-request.yml (1 hunks)
🧰 Additional context used
🪛 actionlint (1.7.4)
.github/workflows/pull-request.yml

327-327: shellcheck reported issue in this script: SC1089:error:34:1: Parsing stopped here. Is this keyword correctly matched up?

(shellcheck)

🪛 yamllint (1.35.1)
.github/workflows/pull-request.yml

[error] 378-378: trailing spaces

(trailing-spaces)


[error] 420-420: trailing spaces

(trailing-spaces)

🔇 Additional comments (4)
.github/workflows/pull-request.yml (4)

395-404: LGTM! Well-implemented cleanup function

The cleanup function correctly preserves the exit code and uses trap for proper cleanup.


378-391: ⚠️ Potential issue

Fix API health check indentation

The inconsistent indentation could cause YAML parsing errors:

-            # Wait for TALAWA API to be healthy 
+          # Wait for TALAWA API to be healthy 
           timeout=60
           until docker-compose -f docker-compose.dev.yaml exec -T talawa-api-dev curl -sf "http://localhost:4000/health" 2>&1 || [ $timeout -eq 0 ]; do
             echo "Waiting for API to start... ($timeout seconds remaining)"
             sleep 1
             ((timeout--))
-           done
+          done

-           if [ $timeout -eq 0 ]; then
+          if [ $timeout -eq 0 ]; then

Likely invalid or redundant comment.

🧰 Tools
🪛 yamllint (1.35.1)

[error] 378-378: trailing spaces

(trailing-spaces)


348-363: ⚠️ Potential issue

Fix MongoDB health check syntax

There are several syntax issues in this section:

-          until docker-compose -f docker-compose.dev.yaml exec -T mongodb mongo --eval "db.runCommand('ping').ok">/dev/null 2>&1 || [ $timeout -eq 0 ]; do
+          until docker-compose -f docker-compose.dev.yaml exec -T mongodb mongo --eval "db.runCommand('ping').ok" >/dev/null 2>&1 || [ $timeout -eq 0 ]; do
           sleep 1
-           ((timeout--))
+            ((timeout--))
           done

-          else
-            echo "MongoDB is ready!"
-          fi
+          echo "MongoDB is ready!"

Likely invalid or redundant comment.


366-376: ⚠️ Potential issue

Fix Redis health check syntax

There are several syntax issues in this section:

-          if[ $timeout -eq 0 ]; then
+          if [ $timeout -eq 0 ]; then
             echo "Error: Redis failed to start within timeout"
             docker-compose -f docker-compose.dev.yaml logs redis-stack-server
             docker-compose -f docker-compose.dev.yaml down -v
             exit 1
-            fi
+          fi

Likely invalid or redundant comment.

Comment on lines +331 to +343
# Verify docker-compose file exists
if [ ! -f "docker-compose.dev.yaml" ]; then
echo "Error: docker-compose.dev.yaml not found"
docker-compose -f docker-compose.dev.yaml logs
exit 1
fi

# Start containers
if ! timeout 300 docker-compose -f docker-compose.dev.yaml up -d --build; then
echo "Failed to start containers"
docker-compose -f docker-compose.dev.yaml logs
exit 1
fi
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Improve error handling for docker-compose file check

The current implementation logs docker-compose logs even when the file doesn't exist, which would fail.

           if [ ! -f "docker-compose.dev.yaml" ]; then
             echo "Error: docker-compose.dev.yaml not found"
-            docker-compose -f docker-compose.dev.yaml logs
             exit 1
           fi
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
# Verify docker-compose file exists
if [ ! -f "docker-compose.dev.yaml" ]; then
echo "Error: docker-compose.dev.yaml not found"
docker-compose -f docker-compose.dev.yaml logs
exit 1
fi
# Start containers
if ! timeout 300 docker-compose -f docker-compose.dev.yaml up -d --build; then
echo "Failed to start containers"
docker-compose -f docker-compose.dev.yaml logs
exit 1
fi
# Verify docker-compose file exists
if [ ! -f "docker-compose.dev.yaml" ]; then
echo "Error: docker-compose.dev.yaml not found"
exit 1
fi
# Start containers
if ! timeout 300 docker-compose -f docker-compose.dev.yaml up -d --build; then
echo "Failed to start containers"
docker-compose -f docker-compose.dev.yaml logs
exit 1
fi

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

♻️ Duplicate comments (1)
.github/workflows/pull-request.yml (1)

331-336: ⚠️ Potential issue

Fix docker-compose logs command placement

The docker-compose logs command will fail if the file doesn't exist.

Apply this fix:

 if [ ! -f "docker-compose.dev.yaml" ]; then
   echo "Error: docker-compose.dev.yaml not found"
-  docker-compose -f docker-compose.dev.yaml logs
   exit 1
 fi
🧹 Nitpick comments (3)
.github/workflows/pull-request.yml (3)

348-352: Fix indentation in MongoDB health check loop

The indentation is inconsistent in the MongoDB health check loop.

Apply this fix:

 until docker-compose -f docker-compose.dev.yaml exec -T mongodb mongosh --eval "db.runCommand({ ping: 1 }).ok">/dev/null 2>&1 || [ $timeout -eq 0 ]; do
-echo "Waiting for MongoDB to be ready..."
-sleep 1
- ((timeout--))
+  echo "Waiting for MongoDB to be ready..."
+  sleep 1
+  ((timeout--))
 done

380-384: Fix indentation in API health check loop

The indentation is inconsistent in the API health check loop.

Apply this fix:

 until docker-compose -f docker-compose.dev.yaml exec -T talawa-api-dev curl -sf "http://localhost:4000/health" 2>&1 || [ $timeout -eq 0 ]; do
-  echo "Waiting for API to start... ($timeout seconds remaining)"
-  sleep 1
-  ((timeout--))
- done
+    echo "Waiting for API to start... ($timeout seconds remaining)"
+    sleep 1
+    ((timeout--))
+done

299-420: Consider adding timeout for the entire job

While individual operations have timeouts, consider adding a timeout for the entire job to prevent long-running workflows.

Add the following at the job level:

 Docker-Check:
   needs: Test-Application
   runs-on: ubuntu-latest
+  timeout-minutes: 15
   steps:
🧰 Tools
🪛 actionlint (1.7.4)

327-327: shellcheck reported issue in this script: SC1069:error:44:3: You need a space before the [

(shellcheck)

🪛 yamllint (1.35.1)

[error] 378-378: trailing spaces

(trailing-spaces)


[error] 420-420: trailing spaces

(trailing-spaces)

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between fbbb7ea and 798b4f7.

📒 Files selected for processing (1)
  • .github/workflows/pull-request.yml (1 hunks)
🧰 Additional context used
🪛 actionlint (1.7.4)
.github/workflows/pull-request.yml

327-327: shellcheck reported issue in this script: SC1069:error:44:3: You need a space before the [

(shellcheck)

🪛 yamllint (1.35.1)
.github/workflows/pull-request.yml

[error] 378-378: trailing spaces

(trailing-spaces)


[error] 420-420: trailing spaces

(trailing-spaces)

🔇 Additional comments (4)
.github/workflows/pull-request.yml (4)

299-320: LGTM! Job configuration looks good.

The job configuration follows GitHub Actions best practices with proper dependency setup and caching.


396-404: LGTM! Cleanup function implementation is correct.

The cleanup function correctly preserves the exit code and ensures proper resource cleanup.


405-419: LGTM! Environment variables are well configured.

The environment variables are properly set with secure token generation using GitHub-provided secrets.


371-376: ⚠️ Potential issue

Fix syntax in Redis health check condition

There's a syntax error in the Redis health check condition.

Apply this fix:

-if[ $timeout -eq 0 ]; then
+if [ $timeout -eq 0 ]; then
   echo "Error: Redis failed to start within timeout"
   docker-compose -f docker-compose.dev.yaml logs redis-stack-server
   docker-compose -f docker-compose.dev.yaml down -v
   exit 1
-  fi
+fi

Likely invalid or redundant comment.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 798b4f7 and 05f9c97.

📒 Files selected for processing (1)
  • .github/workflows/pull-request.yml (1 hunks)
🧰 Additional context used
🪛 yamllint (1.35.1)
.github/workflows/pull-request.yml

[error] 378-378: trailing spaces

(trailing-spaces)


[error] 420-420: trailing spaces

(trailing-spaces)

🔇 Additional comments (5)
.github/workflows/pull-request.yml (5)

299-320: LGTM: Job configuration looks good!

The job configuration follows GitHub Actions best practices with proper dependency setup and caching strategy.


331-336: Remove unnecessary docker-compose logs command

The docker-compose logs command will fail since the file doesn't exist yet.

 if [ ! -f "docker-compose.dev.yaml" ]; then
   echo "Error: docker-compose.dev.yaml not found"
-  docker-compose -f docker-compose.dev.yaml logs
   exit 1
 fi

396-404: LGTM: Cleanup function implementation

The cleanup function correctly preserves the exit code and ensures proper resource cleanup.


405-419: LGTM: Environment variables configuration

The environment variables are well-configured with secure token generation using GitHub-specific variables.


380-391: ⚠️ Potential issue

Fix API health check indentation

The API health check has inconsistent indentation.

-          until docker-compose -f docker-compose.dev.yaml exec -T talawa-api-dev curl -sf "http://localhost:4000/health" 2>&1 || [ $timeout -eq 0 ]; do
-            echo "Waiting for API to start... ($timeout seconds remaining)"
-            sleep 1
-            ((timeout--))
-           done
-
-           if [ $timeout -eq 0 ]; then
-              echo "Error: API failed to start within timeout"
-              docker-compose -f docker-compose.dev.yaml logs
-              docker-compose -f docker-compose.dev.yaml down -v
-              exit 1
-            fi
+          until docker-compose -f docker-compose.dev.yaml exec -T talawa-api-dev curl -sf "http://localhost:4000/health" 2>&1 || [ $timeout -eq 0 ]; do
+            echo "Waiting for API to start... ($timeout seconds remaining)"
+            sleep 1
+            ((timeout--))
+          done
+
+          if [ $timeout -eq 0 ]; then
+            echo "Error: API failed to start within timeout"
+            docker-compose -f docker-compose.dev.yaml logs
+            docker-compose -f docker-compose.dev.yaml down -v
+            exit 1
+          fi

Likely invalid or redundant comment.

Comment on lines +348 to +352
until docker-compose -f docker-compose.dev.yaml exec -T mongodb mongosh --eval "db.runCommand({ ping: 1 }).ok">/dev/null 2>&1 || [ $timeout -eq 0 ]; do
echo "Waiting for MongoDB to be ready..."
sleep 1
((timeout--))
done
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Fix MongoDB health check indentation

The indentation in the MongoDB health check loop is inconsistent.

 until docker-compose -f docker-compose.dev.yaml exec -T mongodb mongosh --eval "db.runCommand({ ping: 1 }).ok">/dev/null 2>&1 || [ $timeout -eq 0 ]; do
-echo "Waiting for MongoDB to be ready..."
-sleep 1
- ((timeout--))
+  echo "Waiting for MongoDB to be ready..."
+  sleep 1
+  ((timeout--))
 done
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
until docker-compose -f docker-compose.dev.yaml exec -T mongodb mongosh --eval "db.runCommand({ ping: 1 }).ok">/dev/null 2>&1 || [ $timeout -eq 0 ]; do
echo "Waiting for MongoDB to be ready..."
sleep 1
((timeout--))
done
until docker-compose -f docker-compose.dev.yaml exec -T mongodb mongosh --eval "db.runCommand({ ping: 1 }).ok">/dev/null 2>&1 || [ $timeout -eq 0 ]; do
echo "Waiting for MongoDB to be ready..."
sleep 1
((timeout--))
done

Comment on lines 367 to 376
until docker-compose -f docker-compose.dev.yaml exec -T redis-stack-server redis-cli ping >/dev/null 2>&1 || [ $timeout -eq 0 ]; do
sleep 1
((timeout--))
done
if [ $timeout -eq 0 ]; then
echo "Error: Redis failed to start within timeout"
docker-compose -f docker-compose.dev.yaml logs redis-stack-server
docker-compose -f docker-compose.dev.yaml down -v
exit 1
fi
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Fix Redis health check indentation and spacing

The Redis health check has inconsistent indentation and spacing issues.

-           timeout=30
-           until docker-compose -f docker-compose.dev.yaml exec -T redis-stack-server redis-cli ping >/dev/null 2>&1 || [ $timeout -eq 0 ]; do
-          sleep 1
-          ((timeout--))
-          done
-          if [ $timeout -eq 0 ]; then
-             echo "Error: Redis failed to start within timeout"
-            docker-compose -f docker-compose.dev.yaml logs redis-stack-server
-             docker-compose -f docker-compose.dev.yaml down -v
-             exit 1
-            fi
+          timeout=30
+          until docker-compose -f docker-compose.dev.yaml exec -T redis-stack-server redis-cli ping >/dev/null 2>&1 || [ $timeout -eq 0 ]; do
+            sleep 1
+            ((timeout--))
+          done
+          if [ $timeout -eq 0 ]; then
+            echo "Error: Redis failed to start within timeout"
+            docker-compose -f docker-compose.dev.yaml logs redis-stack-server
+            docker-compose -f docker-compose.dev.yaml down -v
+            exit 1
+          fi
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
until docker-compose -f docker-compose.dev.yaml exec -T redis-stack-server redis-cli ping >/dev/null 2>&1 || [ $timeout -eq 0 ]; do
sleep 1
((timeout--))
done
if [ $timeout -eq 0 ]; then
echo "Error: Redis failed to start within timeout"
docker-compose -f docker-compose.dev.yaml logs redis-stack-server
docker-compose -f docker-compose.dev.yaml down -v
exit 1
fi
timeout=30
until docker-compose -f docker-compose.dev.yaml exec -T redis-stack-server redis-cli ping >/dev/null 2>&1 || [ $timeout -eq 0 ]; do
sleep 1
((timeout--))
done
if [ $timeout -eq 0 ]; then
echo "Error: Redis failed to start within timeout"
docker-compose -f docker-compose.dev.yaml logs redis-stack-server
docker-compose -f docker-compose.dev.yaml down -v
exit 1
fi

@prayanshchh
Copy link
Author

prayanshchh commented Dec 22, 2024

the docker workflow issue in this pr is related to this issue #2598 , this is the reason I wanted to fix the issue, as the issue is not assigned to anyone, would like to work on it, this won't be completed until and unless that issue is fixed.

thoughts? @palisadoes

@palisadoes
Copy link
Contributor

the docker workflow issue in this pr is related to this issue #2598 , this is the reason I wanted to fix the issue, as the issue is not assigned to anyone, would like to work on it, this won't be completed until and unless that issue is fixed.

thoughts? @palisadoes

Thanks. I've assigned the issue to you. Please fix both in this PR.

@prayanshchh
Copy link
Author

the docker workflow issue in this pr is related to this issue #2598 , this is the reason I wanted to fix the issue, as the issue is not assigned to anyone, would like to work on it, this won't be completed until and unless that issue is fixed.
thoughts? @palisadoes

Thanks. I've assigned the issue to you. Please fix both in this PR.

yes sir, on it

@prayanshchh
Copy link
Author

prayanshchh commented Dec 23, 2024

sir I have fixed redis-stack-server issue and PWD variable issue, I was going through logs and I noticed that we don't have any configuration of replset for mongodb when app is started using docker, hence the application gives warning Session not started --> Not Connected to a replica set!, should I fix this, if yes..in this PR or create another issue for this

@palisadoes

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (5)
setup.ts (3)

1018-1025: Consider validating the 'pwdVariable'

Currently, there's no check to ensure the user-supplied path is valid for Docker. If a user provides an invalid path, it may lead to unexpected behavior when spinning up containers. Validating or clarifying that the path should exist can reduce such issues.


1040-1040: Potential confusion over shell variable 'PWD'

Manually setting process.env.PWD can be confusing since shells typically set this variable automatically. This is not necessarily wrong, but be mindful that it may differ from the shell’s natural behavior.


1047-1047: Logging environment variable 'PWD'

PWD is not sensitive, but ensure that printing environment variables to the console is intentional. In some environments, environment variables may contain secrets or credentials (not the case here, but worth noting).

docker-compose.dev.yaml (1)

62-62: Add a newline at the end of file

YAML linting tools recommend a newline at the end of the file. Ensure there's a trailing newline to satisfy lint checks.

  talawa-network:
     driver: bridge
+
🧰 Tools
🪛 yamllint (1.35.1)

[error] 62-62: no new line character at the end of file

(new-line-at-end-of-file)

.github/workflows/pull-request.yml (1)

378-378: Remove trailing spaces and whitespace

The lines in this file contain trailing spaces, which may fail certain lint checks. It's a minor issue but can easily be resolved:

-  echo "Some line"             
+  echo "Some line"

Also applies to: 383-383, 425-425

🧰 Tools
🪛 yamllint (1.35.1)

[error] 378-378: trailing spaces

(trailing-spaces)

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 05f9c97 and 006092e.

📒 Files selected for processing (4)
  • .env.sample (1 hunks)
  • .github/workflows/pull-request.yml (1 hunks)
  • docker-compose.dev.yaml (2 hunks)
  • setup.ts (1 hunks)
🧰 Additional context used
🪛 yamllint (1.35.1)
.github/workflows/pull-request.yml

[error] 378-378: trailing spaces

(trailing-spaces)


[error] 383-383: trailing spaces

(trailing-spaces)


[error] 425-425: trailing spaces

(trailing-spaces)

docker-compose.dev.yaml

[error] 62-62: no new line character at the end of file

(new-line-at-end-of-file)

🔇 Additional comments (6)
setup.ts (1)

1033-1033: Ensure consistency when assigning 'PWD' to Env Config

By setting config.PWD here, the value is saved in .env for future runs. Ensure any references to the environment variable PWD consistently rely on config.PWD or process.env.PWD.

docker-compose.dev.yaml (3)

38-40: Service name and port mapping

Using an explicit container_name can be useful for local debugging. However, be aware that it can cause naming conflicts. The addition of port mapping 4000:4000 is consistent with the default server port configured in the environment.


49-49: Updated MongoDB URL

The URL now explicitly targets the 'talawa-api' database. This is a correct approach to keep data organized.


52-53: Network usage

These lines define the talawa-network usage for the API service. This is clean and consistent with the other services.

.env.sample (1)

107-110: Additional environment variable 'PWD'

The new environment variable defaults to ".". This is sensible for a Docker working directory, but you might indicate in comments that it's primarily used by Docker-based workflows.

.github/workflows/pull-request.yml (1)

299-410: Docker-Check Job

Introducing a dedicated Docker-Check job is beneficial for ensuring the API starts successfully in a containerized environment. The outlined steps and timeouts for bringing up the container, along with health checks, are thorough.

🧰 Tools
🪛 yamllint (1.35.1)

[error] 378-378: trailing spaces

(trailing-spaces)


[error] 383-383: trailing spaces

(trailing-spaces)

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (6)
.github/workflows/pull-request.yml (6)

311-320: Improve cache key to include Node.js version.

Consider including the Node.js version in the cache key to ensure proper cache isolation between different Node.js versions.

-          key: ${{ runner.os }}-docker-check-${{ hashFiles('**/package-lock.json') }}
+          key: ${{ runner.os }}-node-${{ matrix.node-version }}-docker-check-${{ hashFiles('**/package-lock.json') }}

348-352: Fix MongoDB health check indentation.

The indentation in the MongoDB health check loop is inconsistent.

 until docker-compose -f docker-compose.dev.yaml exec -T mongodb mongosh --eval "db.runCommand({ ping: 1 }).ok">/dev/null 2>&1 || [ $timeout -eq 0 ]; do
-echo "Waiting for MongoDB to be ready..."
-sleep 1
- ((timeout--))
+  echo "Waiting for MongoDB to be ready..."
+  sleep 1
+  ((timeout--))
 done

366-381: Fix Redis health check indentation and spacing.

The Redis health check section has inconsistent indentation and extra spaces.

-           timeout=30
-           until docker-compose -f docker-compose.dev.yaml exec -T redis-stack-server redis-cli ping >/dev/null 2>&1 || [ $timeout -eq 0 ]; do
-          sleep 1
-          ((timeout--))
-          done
-          if [ $timeout -eq 0 ]; then
-             echo "Error: Redis failed to start within timeout"
-             echo "Fetching Redis logs..."
-            docker-compose -f docker-compose.dev.yaml logs redis-stack-server
-            echo "Shutting down Redis..."
-             docker-compose -f docker-compose.dev.yaml down -v
-             exit 1
+          timeout=30
+          until docker-compose -f docker-compose.dev.yaml exec -T redis-stack-server redis-cli ping >/dev/null 2>&1 || [ $timeout -eq 0 ]; do
+            sleep 1
+            ((timeout--))
+          done
+          if [ $timeout -eq 0 ]; then
+            echo "Error: Redis failed to start within timeout"
+            echo "Fetching Redis logs..."
+            docker-compose -f docker-compose.dev.yaml logs redis-stack-server
+            echo "Shutting down Redis..."
+            docker-compose -f docker-compose.dev.yaml down -v
+            exit 1
🧰 Tools
🪛 yamllint (1.35.1)

[error] 378-378: trailing spaces

(trailing-spaces)


383-396: Improve API health check implementation.

The API health check has inconsistent indentation and should use the HEALTH_CHECK_URL environment variable.

-          until docker-compose -f docker-compose.dev.yaml exec -T talawa-api-dev curl -sf "http://localhost:4000/graphql" 2>&1 || [ $timeout -eq 0 ]; do
+          until docker-compose -f docker-compose.dev.yaml exec -T talawa-api-dev curl -sf "${HEALTH_CHECK_URL}/graphql" 2>&1 || [ $timeout -eq 0 ]; do
             echo "Waiting for API to start... ($timeout seconds remaining)"
             sleep 1
             ((timeout--))
-           done
+          done
🧰 Tools
🪛 yamllint (1.35.1)

[error] 383-383: trailing spaces

(trailing-spaces)


401-408: Enhance cleanup function with additional error information.

Consider adding more detailed error information when cleanup fails.

 cleanup() {
   local exit_code=$?
   echo "Cleaning up containers..."
   if ! docker-compose -f  docker-compose.dev.yaml down -v; then
-    echo "Warning: Failed to cleanup containers"
+    echo "Warning: Failed to cleanup containers. Exit code: $?"
+    docker-compose -f docker-compose.dev.yaml ps
   fi
   exit $exit_code
 }

425-425: Remove trailing spaces.

Remove trailing spaces at the end of line 425.

-      MAIL_PASSWORD: ${{secrets.MAIL_PASSWORD}}
-             
+      MAIL_PASSWORD: ${{secrets.MAIL_PASSWORD}}
🧰 Tools
🪛 yamllint (1.35.1)

[error] 425-425: trailing spaces

(trailing-spaces)

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 006092e and 1c57fba.

📒 Files selected for processing (1)
  • .github/workflows/pull-request.yml (1 hunks)
🧰 Additional context used
🪛 yamllint (1.35.1)
.github/workflows/pull-request.yml

[error] 378-378: trailing spaces

(trailing-spaces)


[error] 383-383: trailing spaces

(trailing-spaces)


[error] 425-425: trailing spaces

(trailing-spaces)

🔇 Additional comments (1)
.github/workflows/pull-request.yml (1)

331-336: ⚠️ Potential issue

Fix docker-compose file verification logic.

The current implementation attempts to show docker-compose logs even when the file doesn't exist, which would fail.

 if [ ! -f "docker-compose.dev.yaml" ]; then
   echo "Error: docker-compose.dev.yaml not found"
-  docker-compose -f docker-compose.dev.yaml logs
   exit 1
 fi

Likely invalid or redundant comment.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (2)
.github/workflows/pull-request.yml (2)

401-409: Add error logging to cleanup function

The cleanup function should log the exit code for better debugging.

Apply this diff:

 cleanup() {
   local exit_code=$?
   echo "Cleaning up containers..."
+  echo "Exit code: $exit_code"
   if ! docker-compose -f  docker-compose.dev.yaml down -v; then
     echo "Warning: Failed to cleanup containers"
   fi
   exit $exit_code
 }

410-425: Consider environment variable improvements

A few suggestions for the environment variables:

  1. The HEALTH_CHECK_URL is not used in the script
  2. Consider adding timeout configurations as environment variables

Apply this diff:

     env:
-      HEALTH_CHECK_URL: http://localhost:4000
+      MONGODB_TIMEOUT: 30
+      REDIS_TIMEOUT: 30
+      API_TIMEOUT: 60
       COMPOSE_PROJECT_NAME: pr-${{ github.event.pull_request.number }}
🧰 Tools
🪛 yamllint (1.35.1)

[error] 425-425: trailing spaces

(trailing-spaces)

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1c57fba and 548e83b.

📒 Files selected for processing (1)
  • .github/workflows/pull-request.yml (1 hunks)
🧰 Additional context used
🪛 yamllint (1.35.1)
.github/workflows/pull-request.yml

[error] 378-378: trailing spaces

(trailing-spaces)


[error] 383-383: trailing spaces

(trailing-spaces)


[error] 425-425: trailing spaces

(trailing-spaces)

🔇 Additional comments (4)
.github/workflows/pull-request.yml (4)

299-320: LGTM! Job configuration and dependency setup looks good.

The job configuration correctly:

  • Depends on Test-Application job
  • Uses ubuntu-latest runner
  • Sets up Node.js and caches dependencies

331-336: Remove unnecessary docker-compose logs command

The docker-compose logs command will fail since the file doesn't exist yet.


348-352: Fix MongoDB health check indentation

The indentation in the MongoDB health check loop is inconsistent.


299-425: Verify Docker network configuration

The workflow should verify that the Docker network is properly configured and that containers can communicate with each other.

✅ Verification successful

Docker network configuration is properly defined

The docker-compose.dev.yaml file has a well-configured network setup:

  • All services (mongodb, redis-stack-server, minio, talawa-api-dev) are connected to the same talawa-network
  • The network is properly defined using the bridge driver
  • Service dependencies are correctly specified
  • Internal service communication is enabled through the shared network
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify Docker network configuration
# Check if docker-compose.dev.yaml defines the correct network settings

if [ -f "docker-compose.dev.yaml" ]; then
  echo "Checking network configuration..."
  # Verify network definitions
  yq e '.networks' docker-compose.dev.yaml
  # Verify service network attachments
  yq e '.services.*.networks' docker-compose.dev.yaml
fi

Length of output: 395


Script:

#!/bin/bash
# Let's try to examine the docker-compose.dev.yaml file directly
if [ -f "docker-compose.dev.yaml" ]; then
  echo "Content of docker-compose.dev.yaml:"
  cat docker-compose.dev.yaml
fi

Length of output: 1364

🧰 Tools
🪛 yamllint (1.35.1)

[error] 378-378: trailing spaces

(trailing-spaces)


[error] 383-383: trailing spaces

(trailing-spaces)


[error] 425-425: trailing spaces

(trailing-spaces)

Comment on lines +385 to +389
until docker-compose -f docker-compose.dev.yaml exec -T talawa-api-dev curl -v -X OPTIONS "http://talawa-api-dev:4000/graphql" 2>&1 || [ $timeout -eq 0 ]; do
echo "Waiting for API to start... ($timeout seconds remaining)"
sleep 1
((timeout--))
done
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Improve API health check reliability

The current API health check has a few issues:

  1. Using OPTIONS request might not accurately verify the GraphQL endpoint
  2. Internal container DNS resolution might be unreliable

Apply this diff to improve the health check:

-          until docker-compose -f docker-compose.dev.yaml exec -T talawa-api-dev curl -v -X OPTIONS "http://talawa-api-dev:4000/graphql" 2>&1 || [ $timeout -eq 0 ]; do
+          until docker-compose -f docker-compose.dev.yaml exec -T talawa-api-dev curl -sf -X POST "http://localhost:4000/graphql" \
+            -H 'Content-Type: application/json' \
+            -d '{"query":"{ __typename }"}' 2>&1 || [ $timeout -eq 0 ]; do

Committable suggestion skipped: line range outside the PR's diff.

Copy link
Contributor

@palisadoes palisadoes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. See comments.
  2. It's good to see the test passing.

@@ -138,8 +138,6 @@ export const createVolunteerAndActions = async (): Promise<
});

const today = new Date();
const yesterday = new Date(today);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please exclude this file. It is not relevant to the original issue. You have also changed its logic

const { pwdVariable } = await inquirer.prompt({
type: "input",
name: "pwdVariable",
message:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this added? It should have been fixed in a previously merged PR. Please merge your code with the latest upstream/postgres-develop to be certain.

@palisadoes
Copy link
Contributor

sir I have fixed redis-stack-server issue and PWD variable issue, I was going through logs and I noticed that we don't have any configuration of replset for mongodb when app is started using docker, hence the application gives warning Session not started --> Not Connected to a replica set!, should I fix this, if yes..in this PR or create another issue for this

@palisadoes

  1. Please fix it in this PR.
  2. I thought the PWD issue was already fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants